﻿using System.Web.UI.WebControls;
using System.Collections.Generic;

namespace GameAdmin.Classes
{
    public class HelperMethods
    {
        /// <summary>
        /// Adds pagination to a designated parent control based on received params. Format of the resulting URL is as following: [url][page_number] (e.g. ~/scores/5).
        /// </summary>
        /// <param name="totalItems"></param>
        /// <param name="limit"></param>
        /// <param name="currentIndex"></param>
        /// <param name="urlBase"></param>
        /// <param name="parentControl"></param>
        public static void AddPagination(int totalItems, int limit, int currentIndex, string urlBase, WebControl parentControl)
        {
            int remainder = totalItems % limit;
            int pages = totalItems / limit;

            if (remainder != 0 || pages == 0) pages++;

            for (int i = 1; i <= pages; i++)
            {
                if (currentIndex == i) { parentControl.Controls.Add(new Literal() { Text = currentIndex.ToString() }); }
                else
                {
                    string pageNumber = i.ToString();
                    string url = urlBase;
                    if (i != 1) url += pageNumber;
                    parentControl.Controls.Add(new HyperLink() { Text = pageNumber, NavigateUrl = url });
                }
            }
        }


        /// <summary>
        /// Method to get field types
        /// </summary>
        /// <returns>Dictionary<int, string></returns>
        public static Dictionary<int, string> GetFieldTypes()
        {
            Dictionary<int, string> types = new Dictionary<int, string>();
            types.Add(0, "wall"); 
            types.Add(1, "empty");
            types.Add(2, "guardian");
            types.Add(3, "question");
            types.Add(9, "exit");

            return types;
        }

        /// <summary>
        /// Method to get field types (reverse)
        /// </summary>
        /// <returns>Dictionary<string, int></returns>
        public static Dictionary<string, int> GetFieldTypesReverse()
        {
            Dictionary<string, int> types = new Dictionary<string, int>();
            types.Add("wall", 0);
            types.Add("empty", 1);
            types.Add("guardian", 2);
            types.Add("question", 3);
            types.Add("exit", 9);

            return types;
        }
    }
}